import request from "@/utils/request"
import type {
  OrderLocationDTO,
  OrderEstimateInfoVO,
  RoutePlanningDTO,
  OrderGrabInfoDTO,
  DriverReceiveOrderVO, PassengerReceiveOrderVO, OrderStartInfoVO, OrderPayInfoVO, FeeRuleVO
} from "@/types/order";

/** 预估订单信息 */
export const estimateOrderInfoAPI = (data: RoutePlanningDTO) => {
  return request<OrderEstimateInfoVO>({
    method: "GET",
    url: "/order/order/estimateOrderInfo",
    data
  })
}

/** 下单 */
export const submitOrderAPI = (data: OrderLocationDTO) => {
  return request<number>({
    method: "POST",
    url: "/order/order/submitOrder",
    data
  })
}

/** 取消订单 */
export const cancelOrderAPI = (orderId: number) => {
  return request<null>({
    method: "PUT",
    url: `/order/order/cancelOrder/${orderId}`
  })
}

/** 抢单 */
export const grabOrderAPI = (data: OrderGrabInfoDTO) => {
  return request<null>({
    method: "PUT",
    url: '/order/order/grabOrder',
    data
  })
}

/** 司机获取接单信息 */
export const driverGetReceiveOrderInfoAPI = (orderId: number) => {
  return request<DriverReceiveOrderVO>({
    method: "GET",
    url: '/order/order/driverReceiveOrder/' + orderId
  })
}

/** 乘客获取接单信息 */
export const passengerGetReceiveOrderInfoAPI = (orderId: number) => {
  return request<PassengerReceiveOrderVO>({
    method: "GET",
    url: '/order/order/passengerReceiveOrder/' + orderId
  })
}

/** 开始服务 */
export const startServiceAPI = (orderId: number, tailNumber: string) => {
  return request<null>({
    method: "PUT",
    url: '/order/order/startService/' + orderId + '/' + tailNumber
  })
}

/** 获取订单开始信息 */
export const getOrderStartInfoAPI = (orderId: number) => {
  return request<OrderStartInfoVO>({
    method: "GET",
    url: '/order/order/orderStartInfo/' + orderId
  })
}

/** 到达终点 */
export const arriveEndAPI = (orderId: number) => {
  return request<null>({
    method: "PUT",
    url: '/order/order/arrive/' + orderId
  })
}

/** 获取订单支付信息 */
export const getOrderPayInfoAPI = (orderId: number) => {
  return request<OrderPayInfoVO>({
    method: "GET",
    url: '/order/order/orderPayInfo/' + orderId
  })
}

/** 获取订单费用规则 */
export const getOrderFeeRuleAPI = (orderId: number) => {
  return request<FeeRuleVO>({
    method: "GET",
    url: '/order/order/orderFeeRule/' + orderId
  })
}

/** 支付订单 */
export const payOrderAPI = (orderId: number, couponId: number | null) => {
  return request<FeeRuleVO>({
    method: "PUT",
    url: '/order/order/payOrder?orderId=' + orderId + (couponId != null ? '&couponId=' + couponId : ''),
  })
}
